package top.stacktrace.BookInfo.service;

import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import top.stacktrace.BookInfo.domain.Book;
import top.stacktrace.book.domain.BookPriceVo;
import top.stacktrace.book.service.BookDubboService;

import java.util.Objects;

@Service
@DubboService
public class BookDbService implements BookDubboService {
    @Autowired
    private BookService bookService;

    @Override
    public BookPriceVo getBookPrice(long bookid) {
        Book book = bookService.getBookDetail(bookid);
        if(Objects.nonNull(book)){
            BookPriceVo bv = new BookPriceVo();
            bv.setBookid(bookid);
            bv.setPrice(book.getPrice());
            return bv;
        }
        return null;
    }

    @Override
    public boolean deCreaseBookReserve(long bookid, int reserve) {
        return bookService.reserve(bookid,reserve);
    }
}
